﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AMS.Inventory.DataAccess;
using VitCode.Castle.Helper;

namespace AMSInventoryWeb.UserControls
{
    public partial class PlanAssetInfoCtl : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public string PlanId
        {
            get { return hdPlanId.Value; }
            set { hdPlanId.Value = value; }
        }

        public void SetData()
        {
            if (hdPlanId.Value.Length == 0)
                return;
            SqlHelper sqlHelper = new SqlHelper();
            CoreDataAccess acc = new CoreDataAccess();
            string sql =
                "Select InventoryState,count(*) Amount "
                +"From AmsInventory_InventoryInfo where PlanId='"+PlanId+"' Group by InventoryState";
            DataSet ds = null;
            try
            {
                ds = sqlHelper.ExecuteDataSet(acc.Session, sql);
            }
            finally
            {
                acc.CloseSession();
            }
            if(ds!=null&& ds.Tables.Count>0&& ds.Tables[0].Rows.Count>0)
            {
                foreach(DataRow dr in ds.Tables[0].Rows)
                {
                    string stateVal = dr[0].ToString();
                    string strAmount = dr[1].ToString();
                    var c = FindControl("lbl" + stateVal + "Amount");
                    if (c != null && c is Label)
                        ((Label) c).Text = strAmount;
                }
            }
        }
    }
}